package com.ica.model.contact;

import java.util.Collection;
import java.util.Vector;

/* This class doesn't extend IdentifiableModelObject because
 * an id is provided whenever the contact is created */
/**
 * @author   Hector
 */
public class Contact {
	
	/**
	 */
	private long id;
	/**
	 */
	private String name = null;
	/**
	 */
	private String phoneNumber = null;
	
	/* We need this variable because one contact can be associated to multiple contact groups and we need to know when we edit
	 * a contact group, if the contact belongs or not to the contact group
	 */
	/**
	 */
	private Collection<ContactGroup> contactGroups;
	 
	public Contact(long id, String name, String phoneNumber) {	
		this.id = id;
		this.name = name;
		this.phoneNumber = phoneNumber;
		contactGroups = new Vector<ContactGroup>();
	}
	
	/**
	 * @return
	 * @uml.property  name="id"
	 */
	public long getId() {
		return id;
	}

	/**
	 * @return
	 * @uml.property  name="name"
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param  name
	 * @uml.property  name="name"
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return
	 * @uml.property  name="phoneNumber"
	 */
	public String getPhoneNumber() {
		return phoneNumber;
	}

	/**
	 * @param  phoneNumber
	 * @uml.property  name="phoneNumber"
	 */
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public void addContactGroup(ContactGroup contactGroup) {
		contactGroups.add(contactGroup);
	}

	public void removeContactGroup(ContactGroup contactGroup) {
		contactGroups.remove(contactGroup);
	}

	public boolean belongsTo(ContactGroup contactGroup) {
		return contactGroups.contains(contactGroup);
	}

	/** 
	 * @uml.property name="contactGroups"
	 * @uml.associationEnd multiplicity="(0 -1)" inverse="contacts:com.ica.model.contact.ContactGroup"
	 */
	private Collection<ContactGroup> groups;

	/** 
	 * Getter of the property <tt>contactGroups</tt>
	 * @return  Returns the groups.
	 * @uml.property  name="contactGroups"
	 */
	public Collection<ContactGroup> getContactGroups() {
		return groups;
	}

	/** 
	 * Setter of the property <tt>contactGroups</tt>
	 * @param contactGroups  The groups to set.
	 * @uml.property  name="contactGroups"
	 */
	public void setContactGroups(Collection<ContactGroup> contactGroups) {
		groups = contactGroups;
	}
}
